
#pragma once

#include "fxcc/core/graph/directX11/pch.h"


namespace fxcc
{
	namespace graph
	{
		namespace directX11
		{
			struct FXCC_API Shader
			{
                struct FXCC_API ShaderDesc
                {
                    std::string m_VertCode;
                    std::string m_FragCode;
                    std::string m_GeometryCode;
                    std::string m_TessellationControlCode;
                    std::string m_TessellationEvalutionCode;
                    std::string m_ComputeCode;

                    void OutDir(const std::string& dir)
                    {
                        if (!fs::exists(dir))
                        {
                            fs::create_directories(dir);
                        }
                        OutText((fs::path(dir) / "vert.glsl").string(), m_VertCode);
                        OutText((fs::path(dir) / "frag.glsl").string(), m_FragCode);
                        OutText((fs::path(dir) / "geo.glsl").string(), m_GeometryCode);
                        OutText((fs::path(dir) / "tcs.glsl").string(), m_TessellationControlCode);
                        OutText((fs::path(dir) / "tes.glsl").string(), m_TessellationEvalutionCode);
                        OutText((fs::path(dir) / "compute.glsl").string(), m_ComputeCode);
                    }
                    void OutText(const std::string& p, const std::string v)
                    {
                        std::ofstream ofs(p);
                        ofs << v;
                        ofs.flush();
                        ofs.close();
                    }
                    fxcc::graph::common::VertexType m_VertexType;

                } m_Desc;

				ComPtr<ID3D11VertexShader> m_VertexShader;
				ComPtr<ID3D11PixelShader> m_PixelShader;
				ComPtr<ID3D11InputLayout> m_InputLayout;

				Shader(const std::string& vertCode, const std::string& fragCode, const fxcc::graph::common::VertexType
				& vertexType);

                Shader(const ShaderDesc& desc);

				bool Init();

				void Use();

				static HRESULT CompileShaderFromString(const char* source, const std::string& entry, const std::string& shaderModel, ComPtr<ID3DBlob>& blob);

                std::string testFrag();

                std::string testVert();
			};
		}
	}
}